﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;

namespace Presentation
{
    public partial class AlunoConsulta : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                int index = e.RowIndex;
                int idPessoa = Convert.ToInt32(GridView1.Rows[index].Cells[8].Text);

                using (DBUCNEntities bd = new DBUCNEntities())
                {
                    TBAluno a = bd.TBAlunoes.Single(q => q.IDPessoa == idPessoa);
                    bd.TBAlunoes.DeleteObject(a);
                    bd.SaveChanges();

                    TBpessoa p = bd.TBpessoas.Single(q => q.ID == idPessoa);
                    bd.TBpessoas.DeleteObject(p);
                    bd.SaveChanges();
                }
                Util.UtilCommom.exibirMensagem(this, "Aluno excluído.");
            }
            catch (Exception)
            {
                Util.UtilCommom.exibirMensagem(this, "erro");
            }
        }
    }
}